<?php
namespace app\scodetrace\controller;

class Activities extends \app\common\controller\Base {
	protected $modelname='Activity';
	protected $autoWriteUserId = true;

	protected function _index(){
		$condition=[];
		$param=$this->param;

		if (isset($param['name']))
			$condition[]=['name','like',"%".$param['name']."%"];

		if (isset($param['activity_type']))
			$condition[]=['type_id','in',model('ActivityType')->where('name','like',"%".$param['activity_type']."%")->column("id")];

		$c = [];
		if ($a = isset($param['batch_no']))
			$c[] = ['serial_number','=',$param['batch_no']];
		if ($b = isset($param['batch_name']))
			$c[] = ['name','like',"%".$param['batch_name']."%"];

		if ($a || $b)
			$condition[]=['batch_id','in',model('Batch')->where($c)->column("id")];

		if (isset($param['submitter_time']))
			$condition[]=['submitter_time','between',$param['submitter_time']];

		if (isset($param['submitter'])){
			$condition[]=['submitter_id','in',model('admin/AdminUser')->where('real_name','like','%'.$param['submitter'].'%')->column("id")];
		}

		if (isset($param['start_time']))
			$condition[]=['start_time','between',$param['start_time']];

		if (isset($param['end_time']))
			$condition[]=['end_time','between',$param['end_time']];

		if (isset($param['status']))
			$condition[]=['status','=' ,$param['status']=='true'?1:0];

		return $condition;
	}
}

?>